//
//  PickerViewTest3ViewController.swift
//  iOS-RxSwift-Tutorials_Example
//
//  Created by mengru.tian on 2020/9/22.
//  Copyright © 2020 CocoaPods. All rights reserved.
//

import UIKit
import RxSwift
import RxDataSources

class PickerViewTest3ViewController: UIViewController {
    
    var pickerView:UIPickerView!
    
    //设置文字属性的pickerView适配器
    private let attrStringPickerAdapter = RxPickerViewAttributedStringAdapter<[String]>(
        components: [],
        numberOfComponents: { _,_,_  in 1 },
        numberOfRowsInComponent: { (_, _, items, _) -> Int in
            return items.count}
        ){ (_, _, items, row, _) -> NSAttributedString? in
            return NSAttributedString(string: items[row],
              attributes: [
                NSAttributedStringKey.foregroundColor: UIColor.orange, //橙色文字
                NSAttributedStringKey.underlineStyle:
                    NSUnderlineStyle.styleDouble.rawValue//, //双下划线
                //NSAttributedStringKey.textEffect:
                    //NSAttributedString.TextEffectStyle.letterpressStyle
            ])
        }
    
    let disposeBag = DisposeBag()

    override func viewDidLoad() {
        super.viewDidLoad()

        title = "38.3.修改默认的样式"
        view.backgroundColor = .white
        
        test()
    }
    
    func test() {
        //创建pickerView
        pickerView = UIPickerView()
        self.view.addSubview(pickerView)
         
        //绑定pickerView数据
        Observable.just(["One", "Two", "Tree"])
            .bind(to: pickerView.rx.items(adapter: attrStringPickerAdapter))
            .disposed(by: disposeBag)
    }

}
